package com.jackrain.clouddata.sys.Listenter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jackrain.nea.exception.NDSException;
import com.jackrain.nea.web.query.QueryEngine;
import org.springframework.stereotype.Component;

/**
 * Created by nathan on 2017/8/23.
 */
@Component("com.jackrain.clouddata.sys.Listenter.ConsumeBackProcess")
public class ConsumeBackProcess implements MessageProcess{
    @Override
    public void process(Object paramObject, String tag) throws Exception{
        JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(paramObject,new SerializerFeature[]{SerializerFeature.WriteMapNullValue}));
        String msgkey = jsonObject.getString("MSGKEY");
        String error = jsonObject.getString("ERROR");
        String message = jsonObject.getString("MESSAGE");

        String clientIdSql = "SELECT AD_CLIENT_ID FROM OMS_TAG WHERE ISACTIVE='Y' AND TAGNAME = ?";
        JSONObject clientJson = QueryEngine.getInstance().doQueryObject(clientIdSql,new Object[]{tag});
        if (clientJson == null){
            throw new NDSException("公司ID未找到!");
        }
        Long clientId = clientJson.getLong("AD_CLIENT_ID");

        String updateSql = "update ons_sendmonitor set consumer_error=?,pdesc=?,state=2 where msgkey=?";

        QueryEngine.getInstance().
                executeUpdate(updateSql,
                        new Object[]{error,message,msgkey});

    }
}
